#pragma once
#include "GUIState.h"

namespace CC3501_Main_GUI {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace std;

	/// <summary>
	/// Summary for OpenCSV
	/// </summary>
	public ref class OpenCSV : public System::Windows::Forms::Form
	{
	public:
		OpenCSV(GUIState^ existingState)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
			this->state = existingState;
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~OpenCSV()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  browseInputCSVButton;
	private: System::Windows::Forms::OpenFileDialog^  openCSVDialog;
	private: System::Windows::Forms::TextBox^  inputCSVTextField;
	private: System::Windows::Forms::Label^  selectCSVLbl;
	private: System::Windows::Forms::Button^  cancelBttn;
	private: System::Windows::Forms::Button^  okBttn;

	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>

		// Our save state
		GUIState^ state;

		System::ComponentModel::Container ^components;
		

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->browseInputCSVButton = (gcnew System::Windows::Forms::Button());
			this->openCSVDialog = (gcnew System::Windows::Forms::OpenFileDialog());
			this->inputCSVTextField = (gcnew System::Windows::Forms::TextBox());
			this->selectCSVLbl = (gcnew System::Windows::Forms::Label());
			this->cancelBttn = (gcnew System::Windows::Forms::Button());
			this->okBttn = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// browseInputCSVButton
			// 
			this->browseInputCSVButton->Location = System::Drawing::Point(426, 48);
			this->browseInputCSVButton->Name = L"browseInputCSVButton";
			this->browseInputCSVButton->Size = System::Drawing::Size(75, 23);
			this->browseInputCSVButton->TabIndex = 3;
			this->browseInputCSVButton->Text = L"Browse";
			this->browseInputCSVButton->UseVisualStyleBackColor = true;
			this->browseInputCSVButton->Click += gcnew System::EventHandler(this, &OpenCSV::browseInputCSVButton_Click);
			// 
			// openCSVDialog
			// 
			this->openCSVDialog->FileName = L"chosenCSV";
			this->openCSVDialog->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &OpenCSV::openFileDialog1_FileOk);
			// 
			// inputCSVTextField
			// 
			this->inputCSVTextField->Location = System::Drawing::Point(20, 50);
			this->inputCSVTextField->Name = L"inputCSVTextField";
			this->inputCSVTextField->Size = System::Drawing::Size(400, 20);
			this->inputCSVTextField->TabIndex = 5;

			// TODO - defualt this to the content of state, becareful of nullptr
			// this->inputCSVTextField->Text = this->state->getInputCSVFilePath();
			
			// 
			// selectCSVLbl
			// 
			this->selectCSVLbl->AutoSize = true;
			this->selectCSVLbl->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10));
			this->selectCSVLbl->Location = System::Drawing::Point(17, 21);
			this->selectCSVLbl->Name = L"selectCSVLbl";
			this->selectCSVLbl->Size = System::Drawing::Size(218, 17);
			this->selectCSVLbl->TabIndex = 9;
			this->selectCSVLbl->Text = L"Please select the desired .csv file";
			this->selectCSVLbl->Click += gcnew System::EventHandler(this, &OpenCSV::selectCSVLbl_Click);
			// 
			// cancelBttn
			// 
			this->cancelBttn->Location = System::Drawing::Point(266, 89);
			this->cancelBttn->Name = L"cancelBttn";
			this->cancelBttn->Size = System::Drawing::Size(75, 23);
			this->cancelBttn->TabIndex = 10;
			this->cancelBttn->Text = L"Cancel";
			this->cancelBttn->UseVisualStyleBackColor = true;
			this->cancelBttn->Click += gcnew System::EventHandler(this, &OpenCSV::cancelBttn_Click);
			// 
			// okBttn
			// 
			this->okBttn->Location = System::Drawing::Point(347, 89);
			this->okBttn->Name = L"okBttn";
			this->okBttn->Size = System::Drawing::Size(75, 23);
			this->okBttn->TabIndex = 11;
			this->okBttn->Text = L"OK";
			this->okBttn->UseVisualStyleBackColor = true;
			this->okBttn->Click += gcnew
			System::EventHandler(this, &OpenCSV::okBttn_Click);
			this->okBttn->Click += gcnew System::EventHandler(this, &OpenCSV::okBttn_Click);
			// 
			// OpenCSV
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(507, 123);
			this->Controls->Add(this->okBttn);
			this->Controls->Add(this->cancelBttn);
			this->Controls->Add(this->selectCSVLbl);
			this->Controls->Add(this->inputCSVTextField);
			this->Controls->Add(this->browseInputCSVButton);
			this->Name = L"OpenCSV";
			this->Text = L"Open CSV File";
			this->Load += gcnew System::EventHandler(this, &OpenCSV::OpenCSV_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void OpenCSV_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void openFileDialog1_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) {
			 }
	private: System::Void browseInputCSVButton_Click(System::Object^  sender, System::EventArgs^  e) {				
				 // We do this by calling our openCSVDialog
				 if(openCSVDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
					 // At this point, we know the file was successfully chosen
					 // Set our file input text field to match the file path chosen
					 inputCSVTextField->Text = openCSVDialog->FileName;					 
				 }
				 
			 }
	private: System::Void selectCSVLbl_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void cancelBttn_Click(System::Object^  sender, System::EventArgs^  e) {
				 Close();
			 }
	private: System::Void okBttn_Click(System::Object^  sender, System::EventArgs^  e) {
				// Set the file path on the state object
				this->state->setInputCSVFilePath(inputCSVTextField->Text);

				Close();
			 }
	};
}
